package com.czb.seckill.controller;

import com.czb.seckill.service.UserService;
import com.czb.seckill.vo.LoginVo;
import com.czb.seckill.vo.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * @author: 陈正彬
 *
 */
@Controller
@RequestMapping("/login")
@Slf4j
public class LoginController {

    @Resource
    private UserService userService;

    //进入登入页面
    @RequestMapping("/toLogin")
    public String toLogin() {
        return "login"; //到templates/login.html
    }

    //处理用户登入请求
    @RequestMapping("/doLogin")
    @ResponseBody
    //@Valid 要注意，否则不会校验手机号格式
    public RespBean doLogin(@Valid LoginVo loginVo,
                            HttpServletRequest request, HttpServletResponse response){

        log.info("{}",loginVo);//观察数据
        return userService.doLogin(loginVo,request,response);
    }

}
